use crate::logic;
use crate::view;
use glam::*;
use std::rc::Rc;

use crate::view::*;

#[derive(Clone)]
pub struct GameView {
    pub dim: Vec2,
    pub logic_state: Rc<logic::Floor>,
    pub floor_explorer: view::FloorExplorer,
}

impl GameView {
    pub fn init(dim: Vec2, logic_state: logic::Floor) -> Self {
        let logic_state_rc = Rc::new(logic_state);
        Self {
            dim,
            logic_state: logic_state_rc.clone(),
            floor_explorer: FloorExplorer::new(dim, logic_state_rc),
        }
    }

    pub fn update(&self, frame_number: FrameNumber) -> Self {
        Self {
            floor_explorer: self.floor_explorer.next_frame(frame_number),
            ..self.clone()
        }
    }

    pub fn handle_inputs(
        &self,
        frame_number: FrameNumber,
        inputs: std::collections::hash_set::HashSet<Input>,
    ) -> Self {
        Self {
            floor_explorer: self.floor_explorer.handle_inputs(frame_number, inputs),
            ..self.clone()
        }
    }
}
